package reviewpolymorphismupup;

/**
 * 这个类演示的是有无多态存在的情况的对比
 */
class Shape {
    public void draw() {
        System.out.println("画图形！");
    }
}

class Rect extends Shape {
    @Override
    public void draw() {
        System.out.println("画矩形！");
    }
}

class Cycle extends Shape {
    @Override
    public void draw() {
        System.out.println("画圆！");
    }
}

class Triangle extends Shape {
    @Override
    public void draw() {
        System.out.println("画一个三角形！");
    }
}

class Flower extends Shape {
    @Override
    public void draw() {
        System.out.println("❀！");
    }
}

public class Test {
    //这个drawShapes1方法演示的是假如没有多态存在的情况
    //需求：画一个圆   一个矩形  一个圆  一个矩形  一朵花
    public static void drawShapes1() {
        String[] strings = {"cycle", "rect", "cycle", "rect", "flower"};
        for (String x : strings) {
            if (x.equals("cycle")) {
                Cycle cycle = new Cycle();
                cycle.draw();
            } else if (x.equals("rect")) {
                Rect rect = new Rect();
                rect.draw();
            } else {
                Flower flower = new Flower();
                flower.draw();
            }
        }
    }
    //这个drawShapes方法演示的是有多态存在的情况
    public static void drawShapes() {
        Shape[] shapes = {new Cycle(),new Rect(),new Cycle(),new Rect(),new Flower()};

       /* Shape[] shapes = new Shape[3];
        shapes[0] = new Cycle();
        shapes[1] = new Rect();*/

        for (Shape s : shapes) {
            s.draw();
        }
    }
    public static void main(String[] args) {
        drawShapes();
    }
}